@extends('layouts._app')
@section('content')
    <body>
    <div class="wrap-container">
        @include('layouts._flash')
        <div id="LAY-popup-user-add" class="layui-layer-content">
            <div class="layui-form" lay-filter="layuiadmin-form-role" style="padding: 20px 30px 0 0;">
                {!! Form::open(['route' => ['blog.user.update',$user->id],'class'=>'layui-form','method'=>'put']) !!}
                {!! Form::hidden('submit','8') !!}
                {!! Form::hidden('id',$user->id) !!}
                <div class="layui-form-item">
                    {!! Form::label('','* 用户名：',['class'=>'layui-form-label','style'=>'color:red']) !!}
                    <div class="layui-input-block">
                        {!! Form::text('',"{$user->name}",['required','lay-verify'=>'required','class'=>'layui-input layui-disabled','disabled','placeholder'=>'请输入名称']) !!}
                    </div>
                </div>

                <div class="layui-form-item">
                    {!! Form::label('','手机号：',['class'=>'layui-form-label']) !!}
                    <div class="layui-input-block">
                        {!! Form::text('phone',"{$user->phone}",['class'=>'layui-input','placeholder'=>'请输入手机号']) !!}
                    </div>
                </div>

                <div class="layui-form-item">
                    {!! Form::label('','* 邮箱：',['class'=>'layui-form-label','style'=>'color:red']) !!}
                    <div class="layui-input-inline">
                        {!! Form::email('email',"{$user->email}",['required','id'=>'email_8','lay-verify'=>'required','class'=>'layui-input','placeholder'=>'请输入邮箱号']) !!}
                    </div>
                    <a href="javascript:void(0);"
                       onclick="captcha('{{$user->id}}',8,'{{route('code')}}','{{ csrf_token() }}')"
                       id="code_de_8"
                       style="margin:10px;text-align: center">发送验证码</a>
                    <span style="color: red">注：无更改无需发送</span>
                </div>
                <div class="layui-form-item" id="email_code_8" style="display: none;">
                    {!! Form::label('','邮箱验证码：',['class'=>'layui-form-label']) !!}
                    <div class="layui-input-inline">
                        {!! Form::text('code','',['readonly','id'=>'code_8','class'=>'layui-input','placeholder'=>'无更改无需填写']) !!}
                    </div>
                </div>
                <div class="layui-form-item">
                    {!! Form::label('','密码：',['class'=>'layui-form-label']) !!}
                    <div class="layui-input-block">
                        {!! Form::password('password',['class'=>'layui-input','placeholder'=>'密码可以不用填写,默认原来密码']) !!}
                    </div>
                </div>

                <div class="layui-form-item">
                    {!! Form::label('','真实姓名：',['class'=>'layui-form-label']) !!}
                    <div class="layui-input-block">
                        {!! Form::text('rename',"{$user->info->rename}",['class'=>'layui-input','placeholder'=>'请输入真实姓名']) !!}
                    </div>
                </div>
                <div class="layui-form-item">
                    {!! Form::label('','昵称：',['class'=>'layui-form-label']) !!}
                    <div class="layui-input-block">
                        {!! Form::text('username',"{$user->info->username}",['class'=>'layui-input','placeholder'=>'请输入昵称']) !!}
                    </div>
                </div>
                <div class="layui-form-item">
                    {!! Form::label('','身份证：',['class'=>'layui-form-label']) !!}
                    <div class="layui-input-block">
                        {!! Form::text('card',"{$user->info->card}",['class'=>'layui-input','placeholder'=>'请输入身份证']) !!}
                    </div>
                </div>
                <div class="layui-form-item">
                    {!! Form::label('sex','性别：',['class'=>'layui-form-label']) !!}
                    <div class="layui-input-block">
                        <input type="radio" name="sex" value="1" title="男" @if($user->info->sex == 1) checked @endif>
                        <input type="radio" name="sex" value="2" title="女" @if($user->info->sex == 2) checked @endif>
                    </div>
                </div>
                <div class="layui-form-item">
                    {!! Form::label('','选择地区：',['class'=>'layui-form-label']) !!}
                    <div class="layui-input-block">
                        <div class="layui-input-inline">
                            <select name="province" lay-filter="province" class="province">
                                <option value="">请选择省</option>
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <select name="city" lay-filter="city" disabled>
                                <option value="">请选择市</option>
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <select name="area" lay-filter="area" disabled>
                                <option value="">请选择县/区</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    {!! Form::label('','备注：',['class'=>'layui-form-label']) !!}
                    <div class="layui-input-block">
                        {!! Form::textarea('content',"{$user->info->content}",['class'=>'layui-textarea','placeholder'=>'请输入备注']) !!}
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        {!! Form::submit('确认',['class'=>'layui-btn','lay-filter'=>'formDemo','lay-submit']) !!}
                        {!! Form::reset('重置',['class'=>'layui-btn layui-btn-primary']) !!}
                    </div>
                </div>
                {!! Form::close() !!}

            </div>
        </div>
    </div>
    <script src="{{asset('static/admin/layui/layui.js')}}" type="text/javascript" charset="utf-8"></script>
    <script src="{{asset('js/jquery.min.js')}}" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="{{asset('js/jquery.base64.js')}}"></script>
    <script type="text/javascript" src="{{asset('js/jquery.cookie.js')}}"></script>
    <script type="text/javascript" src="{{asset('js/common.js')}}"></script>
    <script>
        captchaInput(8);
        //Demo
        layui.use(['form', 'layer'], function () {
            var form = layui.form();

            $.ajax({
                type: 'GET',
                url: "/region",
                data: {parent_id: 0, type: 1},
                dataType: "json",
                complete: function (XHR) {
                    XHR = null;
                },
                error: function (xhr) {//获取ajax的错误信息
                    layer.alert(xhr.responseText, "Failed", function () {
                        layer.closeAll();
                    });
                },
                success: function (response) {
                    if (response.code == 403) {
                        layer.msg(response.msg, {icon: 4, time: 3000})
                        return false;
                    }
                    if (response.code != 200) {
                        layer.msg(response.msg, {icon: 5, time: 3000});
                        return false;
                    }
                    var proHtml = '';
                    var pro = response.data;
                    var id = "{{$user->info->province}}";
                    for (var i = 0; i < pro.length; i++) {
                        if (id == pro[i].id) {
                            $("select[name=province]").val(pro[i].id);
                            proHtml += '<option value="' + pro[i].id + '" selected="selected" >' + pro[i].name + '</option>';
                        } else {
                            proHtml += '<option value="' + pro[i].id + '">' + pro[i].name + '</option>';
                        }
                    }
                    //初始化省数据
                    $("select[name=province]").append(proHtml);
                    form.render();
                    var value = 0;
                    $("select[name=area]").html('<option value="">请选择县/区</option>');
                    value = id;
                    if (value > 0) {
                        $.ajax({
                            type: 'GET',
                            url: "/region",
                            data: {parent_id: value, type: 2},
                            dataType: "json",
                            complete: function (XHR) {
                                XHR = null;
                            },
                            error: function (xhr) {//获取ajax的错误信息
                                layer.alert(xhr.responseText, "Failed", function () {
                                    layer.closeAll();
                                });
                            },
                            success: function (res) {
                                if (res.code == 403) {
                                    layer.msg(res.msg, {icon: 4, time: 3000})
                                    return false;
                                }
                                if (res.code != 200) {
                                    layer.msg(res.msg, {icon: 5, time: 3000});
                                    return false;
                                }
                                citys(res.data);
                                form.render();
                            }
                        });
                    } else {
                        $("select[name=city]").attr("disabled", "disabled");
                    }
                    form.on('select(province)', function (proData) {
                        $("select[name=area]").html('<option value="">请选择县/区</option>');
                        value = proData.value;
                        if (value > 0) {
                            $.ajax({
                                type: 'GET',
                                url: "/region",
                                data: {parent_id: value, type: 2},
                                dataType: "json",
                                complete: function (XHR) {
                                    XHR = null;
                                },
                                error: function (xhr) {//获取ajax的错误信息
                                    layer.alert(xhr.responseText, "Failed", function () {
                                        layer.closeAll();
                                    });
                                },
                                success: function (res) {
                                    if (res.code == 403) {
                                        layer.msg(res.msg, {icon: 4, time: 3000})
                                        return false;
                                    }
                                    if (res.code != 200) {
                                        layer.msg(res.msg, {icon: 5, time: 3000});
                                        return false;
                                    }
                                    citys(res.data);
                                }
                            });
                        } else {
                            $("select[name=city]").attr("disabled", "disabled");
                        }
                    });
                }
            });

            function citys(citys) {
                var cityHtml = '<option value="">请选择市</option>';
                var id = "{{$user->info->city}}";
                for (var i = 0; i < citys.length; i++) {
                    if (id == citys[i].id) {
                        $("select[name=city]").val(citys[i].id);
                        cityHtml += '<option value="' + citys[i].id + '" selected="selected">' + citys[i].name + '</option>';
                    } else {
                        cityHtml += '<option value="' + citys[i].id + '">' + citys[i].name + '</option>';
                    }
                }
                $("select[name=city]").html(cityHtml).removeAttr("disabled");
                form.render();
                var value = id;
                if (value > 0) {
                    $.ajax({
                        type: 'GET',
                        url: "/region",
                        data: {parent_id: value, type: 3},
                        dataType: "json",
                        complete: function (XHR) {
                            XHR = null;
                        },
                        error: function (xhr) {//获取ajax的错误信息
                            layer.alert(xhr.responseText, "Failed", function () {
                                layer.closeAll();
                            });
                        },
                        success: function (response) {
                            if (response.code == 403) {
                                layer.msg(response.msg, {icon: 4, time: 3000})
                                return false;
                            }
                            if (response.code != 200) {
                                layer.msg(response.msg, {icon: 5, time: 3000});
                                return false;
                            }
                            var pro = response.data;
                            areas(pro);
                        }
                    });
                } else {
                    $("select[name=area]").attr("disabled", "disabled");
                }
                form.on('select(city)', function (cityData) {
                    var value = cityData.value;
                    if (value > 0) {
                        $.ajax({
                            type: 'GET',
                            url: "/region",
                            data: {parent_id: value, type: 3},
                            dataType: "json",
                            complete: function (XHR) {
                                XHR = null;
                            },
                            error: function (xhr) {//获取ajax的错误信息
                                layer.alert(xhr.responseText, "Failed", function () {
                                    layer.closeAll();
                                });
                            },
                            success: function (response) {
                                if (response.code == 403) {
                                    layer.msg(response.msg, {icon: 4, time: 3000})
                                    return false;
                                }
                                if (response.code != 200) {
                                    layer.msg(response.msg, {icon: 5, time: 3000});
                                    return false;
                                }
                                var pro = response.data;
                                areas(pro);
                            }
                        });
                    } else {
                        $("select[name=area]").attr("disabled", "disabled");
                    }
                });
            }

            function areas(areas) {
                var areaHtml = '<option value="">请选择县/区</option>';
                var id = "{{$user->info->area}}";
                for (var i = 0; i < areas.length; i++) {
                    if (id == areas[i].id) {
                        $("select[name=area]").val(areas[i].id);
                        areaHtml += '<option value="' + areas[i].id + '" selected>' + areas[i].name + '</option>';
                    } else {
                        areaHtml += '<option value="' + areas[i].id + '">' + areas[i].name + '</option>';
                    }
                }
                $("select[name=area]").html(areaHtml).removeAttr("disabled");
                form.render();
            }

            //监听提交
            form.on('submit(formDemo)', function (data) {
            });
        })
    </script>
    </body>
@endsection
